home *** CD-ROM | disk | FTP | other *** search
/ SPACE 1 / SPACE - Library 1 - Volume 1.iso / program / 441 / dlibs12 / shell.c < prev    next >
C/C++ Source or Header  |  1990-11-23  |  1KB  |  45 lines

  1. #include <osbind.h>
  2. #include <stdio.h>
  3.  
  4. extern char    *_base;
  5.  
  6. void shell()
  7.     {
  8.     register char *p, *q;
  9.     register int (*shell)();
  10.     int rv = 0;
  11.     char command[128];
  12.     char *getenv(), *strtok(), *fullpath();
  13.     int getch(), putch();
  14.  
  15.     /* SHELL= variable? */
  16.     if((p = getenv("SHELL")) && (*p))    /* SHELL is valid? */
  17.         {
  18.         q = (char *) Super(0L);
  19.         shell = (int (*)()) *((long *) 0x4F6L);    /* get _shell_p value */
  20.         Super(q);
  21.         if((shell) &&                /* shell available */
  22.            (((long) shell) < ((long) _base)) &&    /* reasonable value */
  23.            (strncmp(shell, "PATH", 4)))     /* not corrupted */
  24.             {
  25.             rv = (*shell)(p);        /* call shell */
  26.             return;
  27.             }
  28.         forklp(p, p, NULL);            /* execute shell */
  29.         wait(&rv);
  30.         return;
  31.         }
  32.     /* internal command line interface */
  33.     for(;;)
  34.         {
  35.         cprintf("%s> ", fullpath(NULL, ""));    /* cwd as prompt */
  36.         getln(NULL, getch, putch, command, 128);/* editable field */
  37.         cputs("\r\n");
  38.         if(command[0] == '\0')            /* ignore blank lines */
  39.             continue;
  40.         if(!stricmp(command, "exit"))        /* leave the shell */
  41.             return;
  42.         system(command);            /* execute a command */
  43.         }
  44.     }
  45.